#include "GameMsgPack.h"

CGameMsgPack::CGameMsgPack(void)
{
	m_nID = (UINT)(-1);
	m_nDataSize = 0;
	memset(m_buf,0,sizeof(m_buf));
}

CGameMsgPack::~CGameMsgPack(void)
{
}

void CGameMsgPack::SetData(UINT nMsgID,const void* pData,UINT nDataSize)
{
	m_nID = nMsgID;
	if (pData == NULL && nDataSize!= 0)
	{
		assert(0);
		return;		
	}
	if (pData != NULL && nDataSize == 0)
	{
		assert(0);
		return;		
	}
	if (nDataSize >= MaxBufferLength)
	{
		assert(0);
		return;	
	}
	m_nDataSize = nDataSize;
	if (pData == NULL && nDataSize == 0)
	{
		return;
	}	
	memcpy(m_buf,pData,nDataSize);
	m_buf[m_nDataSize] = '\0';
	return;
}

void CGameMsgPack::GetData(UINT& nMsgID,void* pData)
{
	nMsgID = m_nID;
    memcpy(pData,m_buf,m_nDataSize);
	return;
}

UINT CGameMsgPack::GetMsgLength()
{
	return (sizeof(m_nID)+sizeof(m_nDataSize)+m_nDataSize+8);
}
